<template>
  <!-- 添加或修改角色配置对话框 -->
  <el-dialog :title="title" :visible.sync="open" width="850px">
    <el-row>
      <el-col :span="24">
        <el-table ref="InterviewerTable" v-loading="loading" :data="userList" @selection-change="handleSelectionChangeFn">
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column label="用户名称" prop="nickName" />
          <el-table-column label="技术类型" prop="jobType" :show-overflow-tooltip="true" >
            <template slot-scope="scope">
              <span>{{ ifType(scope.row.jobType) }}</span>
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getListFn"
        />
      </el-col>
    </el-row>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitFormFn">确 定</el-button>
      <el-button @click="cancelFn">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import { apiInterviewAdd } from "../../../../api/pmp/api.recruit";
  import { apiListUser } from "../../../../api/system/user";

  export default {
    name: 'InterviewerDetail',
    data () {
      return {
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 弹出层标题
        title: "新增面试官",
        // 是否显示弹出层
        open: false,
        // 工时选择数组
        timeData: [],
        // 用户列表相关
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 总条数
        total: 0,
        // 技术类型数据字典
        typeOptions: [],
        // 用户表格数据
        userList: null,
        // 查询参数
        queryParams: {
          isInterview: "yes",
          pageNum: 1,
          pageSize: 10,
          userName: undefined,
          phonenumber: undefined,
          status: undefined,
          deptId: undefined
        },
      };
    },
    computed: {
      ifType () {
        return (val)=> {
          return (this.typeOptions.find((item) => item.dictValue == val) || {}).dictLabel;
        };
      }
    },
    created() {
      this.apiGetDicts("technology_post_type").then(response => {
        this.typeOptions = response.data;
      });
      this.getListFn();
    },
    methods: {
      /** 查询用户列表 */
      getListFn() {
        this.loading = true;
        apiListUser(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          this.userList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
        );
      },
      // 多选框选中数据
      handleSelectionChangeFn(selection) {
        this.ids = selection.map(item => item.userId);
        this.single = selection.length != 1;
        this.multiple = !selection.length;
      },
      // 取消按钮
      cancelFn() {
        this.open = false;
        this.resetFn();
      },
      /** 提交按钮 */
      submitFormFn: function() {
        if(!this.ids || this.ids.length == 0){
          this.msgError("请选择用户");
          return;
        }
        apiInterviewAdd((this.ids || []).join(',')).then(response => {
          if (response.code === 200) {
            this.msgSuccess(response.msg);
            this.open = false;
            this.resetFn();
            this.$parent.getListFn();
          } else {
            this.msgError(response.msg);
          }
        });
      },
      // 打开页面
      openDetail(){
        this.open = true;
      },
      // 表单重置
      resetFn() {
        // if (this.$refs.menu != undefined) {
        //   this.$refs.menu.setCheckedKeys([]);
        // }
        this.ids = [];
        this.$refs.InterviewerTable.clearSelection();
        // this.resetForm("form");
      }

    }
  };
</script>
